<template>
  <div class="cubeNavBox" :style="outModuleCss">
    <div :style="moduleBgCss" class="module-bg"></div>
    <div class="cubeNavContent">
      <!-- 单列滑动 -->
      <div class="style1" v-if="propsData.params.drain == 2">
        <div class="pageList">
          <div
            class="pageItem"
            v-for="(page, pageIndex) in pages"
            :key="pageIndex"
          >
            <div class="navList">
              <div
                class="navBox"
                v-for="(item, index) in page"
                :style="{
                  width:
                    propsData.params.columnNumber == 3
                      ? '33.3%'
                      : propsData.params.columnNumber == 4
                      ? '25%'
                      : propsData.params.columnNumber == 5
                      ? '20%'
                      : '',
                }"
                :key="index"
              >
                <div class="navItem" @click.stop="changeNav(item)">
                  <img
                    :src="item.iconUrl"
                    alt=""
                    v-if="item.iconUrl && item.iconUrl != ''"
                  />
                  <img
                    src="@/assets/images/diy/default_img.png"
                    alt=""
                    v-else
                  />
                  <span :style="item.css">{{ item.name }}</span>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="scrollBox">
          <span></span>
        </div>
      </div>

      <!-- 整页滑动 -->
      <div class="style2" v-if="propsData.params.drain == 1">
        <el-carousel indicator-position="none" :autoplay="false" :height="propsData.params.numberOfLines == 1? '71px':'142px'">
          <el-carousel-item
            class="pageItem"
            v-for="(page, pageIndex) in pages"
            :key="pageIndex"
          >
            <div class="navList">
              <div
                class="navBox"
                v-for="(item, index) in page"
                :style="{
                  width:
                    propsData.params.columnNumber == 3
                      ? '33.3%'
                      : propsData.params.columnNumber == 4
                      ? '25%'
                      : propsData.params.columnNumber == 5
                      ? '20%'
                      : '',
                }"
                :key="index"
              >
                <div class="navItem" @click.stop="changeNav(item)">
                  <img
                    :src="item.iconUrl"
                    alt=""
                    v-if="item.iconUrl && item.iconUrl != ''"
                  />
                  <img
                    src="@/assets/images/diy/default_img.png"
                    alt=""
                    v-else
                  />
                  <span :style="item.css">{{ item.name }}</span>
                </div>
              </div>
            </div>
          </el-carousel-item>
        </el-carousel>
        <div class="scrollBox">
          <span></span>
        </div>
      </div>

      <!-- 固定显示 -->
      <div class="style3" v-if="propsData.params.drain == 3">
        <div class="pageList">
          <div
            class="pageItem"
            v-for="(page, pageIndex) in pages"
            :key="pageIndex"
          >
            <div class="navList">
              <div
                class="navBox"
                v-for="(item, index) in page"
                :style="{
                  width:
                    propsData.params.columnNumber == 3
                      ? '33.3%'
                      : propsData.params.columnNumber == 4
                      ? '25%'
                      : propsData.params.columnNumber == 5
                      ? '20%'
                      : '',
                }"
                :key="index"
              >
                <div class="navItem" @click.stop="changeNav(item)">
                  <img
                    :src="item.iconUrl"
                    alt=""
                    v-if="item.iconUrl && item.iconUrl != ''"
                  />
                  <img
                    src="@/assets/images/diy/default_img.png"
                    alt=""
                    v-else
                  />
                  <span :style="item.css">{{ item.name }}</span>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
function group(array, subGroupLength) {
  let index = 0;
  let newArray = [];
  while (index < array.length) {
    newArray.push(array.slice(index, (index += subGroupLength)));
  }
  return newArray;
}
import { mixinsModuleCss } from "@/components/DiyNew/diy/mixins/index.js";
export default {
  props: {
    propsData: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },
  mixins: [mixinsModuleCss],
  mounted() {
    console.log(this.propsData, "cubeNav");
  },
  computed: {
    pages() {
      let count = Math.ceil(
        this.propsData.params.list.length /
          (this.propsData.params.columnNumber *
            this.propsData.params.numberOfLines)
      );
      if (count > 0) {
        return group(
          this.propsData.params.list,
          this.propsData.params.columnNumber *
            this.propsData.params.numberOfLines
        );
      } else {
        return [];
      }
    },
  },
  methods: {
    changeNav(e) {
      console.log(e);
      this.$emit("chooseMoudle", e);
    },
  },
};
</script>

<style lang="scss" scoped>
.cubeNavBox {
  width: 100%;
  position: relative;
  .cubeNavContent {
    padding: 10px 10px 0 10px;
  }
  .navList {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    .navBox {
      display: flex;
      align-items: center;
      justify-content: center;
      margin-bottom: 10px;
    }
    .navItem {
      width: 40px;
      max-width: 40px;
      display: flex;
      flex-direction: column;
      align-items: center;
      position: relative;
      img {
        width: 40px;
      }
      span {
        white-space: nowrap;
        margin-top: 3px;
        white-space: nowrap;
      }
    }
    .navItem:hover::before {
      cursor: pointer;
      content: "\e657";
      font-family: "iconfont";
      position: absolute;
      right: 0;
      top: 0;
      width: 20px;
      height: 20px;
      background-color: #1890fc;
      border-radius: 0 0 0 4px;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 14px;
      color: #fff;
    }
    .navItem:hover::after {
      cursor: pointer;
      content: "";
      position: absolute;
      width: 100%;
      height: 100%;
      top: 0;
      left: 0;
      border: 1px solid #1890fc;
    }
  }
}
.style1 {
  width: 100%;
  .pageList::-webkit-scrollbar {
    width: 10px;
    height: 5px;
    /**/
  }
  .pageList::-webkit-scrollbar-track {
    background: rgb(239, 239, 239);
    border-radius: 2px;
  }
  .pageList::-webkit-scrollbar-thumb {
    background: #bfbfbf;
    border-radius: 10px;
  }
  .pageList::-webkit-scrollbar-thumb:hover {
    background: #333;
  }
  .pageList::-webkit-scrollbar-corner {
    background: #179a16;
  }
  .pageList {
    width: 100%;
    display: flex;
    align-items: stretch;
    flex-wrap: nowrap;
    overflow-x: auto;
    .pageItem {
      width: 100%;
      min-width: 100%;
    }
  }
}
.style2 {
  width: 100%;
  z-index: 10000;
}
.style3 {
  .pageList {
    width: 100%;
    .pageItem {
      width: 100%;
      min-width: 100%;
    }
  }
}
.module-bg {
  width: 100%;
  height: 100%;
  z-index: -1;
  position: absolute;
  left: 0;
  top: 0;
}
.ant-carousel .custom-slick-arrow {
  width: 25px;
  height: 25px;
  font-size: 25px;
  color: #fff;
  background-color: rgba(31, 45, 61, 0.11);
  opacity: 0.3;
  z-index: 1000;
}
.ant-carousel .custom-slick-arrow:before {
  display: none;
}
.ant-carousel .custom-slick-arrow:hover {
  opacity: 0.5;
}
.scrollBox {
  width: 40px;
  height: 3px;
  background-color: rgba(0, 0, 0, 0.1);
  margin: 5px auto;
  border-radius: 3px;
  overflow: hidden;
  position: relative;
  span {
    position: absolute;
    left: 0;
    top: 0;
    width: 20px;
    height: 100%;
    background-color: #262626;
  }
}
</style>